package com.ny.kind;

public class Test23 {
        public static void main(String[] args) {
            abstract class Insurance {
                protected double value;

                public Insurance(double value) {
                    this.value = value;
                }

                public abstract double calculateBasePremium();

                public abstract double calculatePremium();
            }

            class CarInsurance extends Insurance {
                private int accidentCount;

                public CarInsurance(double carValue, int accidentCount) {
                    super(carValue);
                    this.accidentCount = accidentCount;
                }

                @Override
                public double calculateBasePremium() {
                    return value * 0.02;
                }

                @Override
                public double calculatePremium() {
                    double basePremium = calculateBasePremium();
                    if (accidentCount == 0) {
                        return basePremium;
                    } else if (accidentCount == 1) {
                        return basePremium * 1.1;
                    } else {
                        return basePremium * 1.2;
                    }
                }
            }

            class HomeInsurance extends Insurance {
                private int houseArea;

                public HomeInsurance(double houseValue, int houseArea) {
                    super(houseValue);
                    this.houseArea = houseArea;
                }

                @Override
                public double calculateBasePremium() {
                    return value * 0.015;
                }

                @Override
                public double calculatePremium() {
                    double basePremium = calculateBasePremium();
                    if (houseArea > 100) {
                        return basePremium * 1.05;
                    }
                    return basePremium;
                }
            }

            class InsurancePolymorphism {
                public static void main(String[] args) {
                    CarInsurance carInsurance = new CarInsurance(200000, 1);
                    System.out.println("车险保费: " + carInsurance.calculatePremium());

                    HomeInsurance homeInsurance = new HomeInsurance(1500000, 120);
                    System.out.println("家庭基本险保费: " + homeInsurance.calculatePremium());
                }
            }
        }
    }
